package cn.edu.gdu.quizpractice.controller.mini;

import cn.edu.gdu.quizpractice.entity.ApiResult;
import cn.edu.gdu.quizpractice.entity.Bank;
import cn.edu.gdu.quizpractice.entity.ChoiceQuestion;
import cn.edu.gdu.quizpractice.service.IBankService;
import cn.edu.gdu.quizpractice.service.IChoiceQuestionService;
import io.micrometer.core.annotation.Timed;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: Aubery
 * @Date: 2025-04-16-15:37
 * @Description:
 */
@RestController
@RequestMapping("/mini/banks")
@Timed(value = "mini/bankController",description = "BankController")
public class MiniBankController {

    @Autowired
    private IBankService bankService;

    @Autowired
    private IChoiceQuestionService choiceQuestionService;

    /**
     * 获取已审核的题库
     * @return 已审核的题库信息
     * @description 小程序端调用此接口获取已审核的题库信息，用于展示题库列表。
     */

    @GetMapping("/getAuditedBanks")
    public ApiResult showAuditedBanks() {
        List<Bank> banks = bankService.showAuditedBanks();
        if (banks == null)
            return ApiResult.fail("没有题库已审核完毕,请稍等......");
        return ApiResult.success(banks);
    }

    @GetMapping("getBanksInfo")
    public ApiResult getBanksInfo(@RequestParam("bankName") String bankName) {
        Bank bank = bankService.findBankInfoByName(bankName);
        if (bank == null)
            return ApiResult.fail("题库不存在或题库未审核完毕,请稍等......");
        return ApiResult.success(bank);
    }

    /**
     * 获取某题库所有题目信息
     * @return List<ChoiceQuestion>
     * @description 小程序端调用此接口获取某个题库的所有题目信息。
     */
    @GetMapping("/getQuestionsByBankName")
    public ApiResult getQuestionsByBankName(String bankName) {
        List<ChoiceQuestion> questionsByBankName = bankService.findQuestionsByBankName(bankName);
        if (questionsByBankName == null)
            return ApiResult.fail("题库不存在或题库未审核完毕,请稍等......");
        return ApiResult.success(questionsByBankName);
    }

}
